package com.kadron.dao;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.EntityManager;

import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.intercept.BypassInterceptors;

import com.kadron.entity.News;
import com.kadron.entity.NewsLetter;

@AutoCreate
@BypassInterceptors
@Name("newsDAO")
public class KNewsDAO extends KDAO<News> implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8342508881559866425L;

	@SuppressWarnings("unchecked")
	public List<NewsLetter> getNews(Date date) {
		EntityManager em = getEntityManager();
		return em.createQuery("SELECT DISTINCT e FROM News e WHERE e.processed = FALSE AND e.start < :moment AND e.active = TRUE")
				.setParameter("moment", date)
				.getResultList();
	}
	
}
